# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=unicodecsv
pkgbase=mingw-w64-python2-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-python2-${_realname}"
pkgver=0.14.1
pkgrel=3
pkgdesc="Python2's stdlib csv module is nice, but it doesn't support unicode. This module is a drop-in replacement which *does*. (mingw-w64)"
arch=('any')
url="https://github.com/jdunck/python-unicodecsv"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python2")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools")
source=("${_realname}-$pkgver.tar.gz"::"https://github.com/jdunck/python-unicodecsv/archive/$pkgver.tar.gz")
sha512sums=('9135c0f3702d60d72b2544476feb9e924b8d592e06d21eca98cd10406de9ecca49bcde9e9bfa7baeb4358dddf86ad737e155355d8b927de5b93912201a8d87b0')

prepare() {
  sed -i 's/unittest2/unittest/' python-unicodecsv-$pkgver/{runtests.py,unicodecsv/test.py}
  sed -i '/unittest2/d' python-unicodecsv-$pkgver/setup.py

  rm -rf python2-build-${CARCH} | true
  cp -r "python-${_realname}-${pkgver}" "python2-build-${CARCH}"
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
  export PBR_VERSION=$pkgver
}

build() {
  cd "${srcdir}/python2-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python2 setup.py build
}

check() {
  cd "${srcdir}/python2-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python2 setup.py test || true
}

package() {
  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}
